package designpattern;

/**
 * @Author: jeason
 * @Description: 建造者模式
 * @Date: 2020/7/19 14:27
 */
public class Hero {
    private String profession;
    private String name;
    private String weapon;

    private Hero(HeroBuilder builder) {
        this.profession = builder.profession;
        this.name = builder.name;
        this.weapon = builder.weapon;
    }


    public static class HeroBuilder {
        private String profession;
        private String name;
        private String weapon;

        public HeroBuilder(String profession, String name) {
            if (profession == null || name == null) {
                throw new IllegalArgumentException("profession and name can not be null");
            }
            this.profession = profession;
            this.name = name;
        }


        public HeroBuilder withWeapon(String weapon) {
            this.weapon = weapon;
            return this;
        }

        public Hero build() {
            return new Hero(this);
        }
    }

    public static void main(String[] args) {
        Hero mage = new HeroBuilder("Profession.MAGE", "Riobard").withWeapon("Weapon.DAGGER").build();
        System.out.println(mage.name);
    }
}
